<?php
namespace App\Services;
/**
 * 
 * 快递100控制器
 * 
 * @author maqu
 *
 */
class KuaidiService extends BaseService {

    var $_gateway   =   'http://api.kuaidi100.com/api?';
    
    var $_order_state = array(
    	'0' => '在途',
		'1' => '揽件',
		'2' => '疑难',
		'3' => '签收成功',
		'4' => '退签',
		'5' => '派件中',
		'6' => '退货中'
    );
    
    public function getHistory($nu=0,$com='')
	{
		header('Access-Control-Allow-Origin:*');
	    $param = sprintf('id=%s&com=%s&nu=%s',env('KUAIDI_100_KEY'),$com,$nu);
	    $url = $this->_gateway . $param;

		$curl = curl_init();
    	curl_setopt ($curl, CURLOPT_URL, $url);
    	curl_setopt ($curl, CURLOPT_HEADER,0);
    	curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
    	curl_setopt ($curl, CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']);
    	curl_setopt ($curl, CURLOPT_TIMEOUT,5);
    
        $get_content = curl_exec($curl);
     	curl_close ($curl);
     	
     	$obj = json_decode($get_content);

     	if($obj->status === "1") {
         	$comCode = $obj->com;// 物流公司
         	$arrData = $obj->data;
//    		$results = DB::table('express_company')
//    					->where('code', $comCode)->first();
//
//    		$comName = count($results)===0?$comCode:$results->name;
//         	return View::make('Orders/express_history')->with('content',$get_content)->with('order_no',$obj->nu)->with('comName', $comName)
//         								->with('state', $this->_order_state[$obj->state])
//         								->with('infolist',$arrData);
     	} else 
     	{
     	    return $obj->message;
     	}
	}

}
